package types;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

public class Main extends Algorithms{

	static ArrayList<Vertex> vertex_list;				// vertices w/ edges located by source
	static ArrayList<Vertex> vertex_by_destination;		// vertices w/ edges located by destination
	static HashMap <String, Edge> vertex_hash;
	static ArrayList <Edge> penalty_edges;				// holds all penalty edges
	static ArrayList <Edge> bad_edges;					// the 10% worst edges 
	static int max_weight;								// weight of a penalty edge (10 * max real edge weight)
	static short branching = 10;						// number of branches that occurs at the start. ~10 seems the most reasonable
	static short branches = 2;							// number of branches per branch session

	//static File output = new File ("..\\TSP\\test\\solution.txt");
	//static File input = new File ("..\\TSP\\test\\practice_tsp_1\\ch150.tsp.graph");
	//static File sol = new File ("..\\TSP\\test\\practice_tsp_1\\20.tsp.sol");

	//static File output = new File ("..\\TSP\\test\\solution.txt");
	//static File input = new File ("..//TSP//test//practice_tsp_1//ch150.tsp.graph");
	//static File sol = new File ("..\\TSP\\test\\practice_tsp_1\\ch150.tsp.sol");

	
	public static void main(String[] args) {

		vertex_list = new ArrayList <Vertex>();
		vertex_by_destination = new ArrayList <Vertex>();
		vertex_hash = new HashMap <String, Edge>();			/* has all natural edges stored for faster access
															 * to get an edge A -> B, call .get(A+","+B) and it returns the edge
															 */
		penalty_edges = new ArrayList <Edge> ();			// holds all penalty edges
		bad_edges = new ArrayList <Edge> ();

		//initialize (input);
		initialize(new File(args[0]));
		
		Algorithms.solution = branched_greedy();
		Algorithms.solution = sort_for_2_opt(Algorithms.solution);
		
		
		
		for (int i = 0; i < 17; i++)
		{
			find_shitty_edges();
			remove(bad_edges);
			bad_edges.clear();
		}
		
		
		//store_penalty_edges();
		
		/*
		while(penalty_edges.size() > 1)
		{	
			System.err.println(penalty_edges.size());
			remove(penalty_edges);
			store_penalty_edges();
		} */
		
		//System.err.println("we made it this far");
		
		Algorithms.solution.sum = sol_dist(Algorithms.solution,0);
		int avg_weight = (int) (Algorithms.solution.sum / Algorithms.solution.edges.size());
		
		two_opt(avg_weight);
		Algorithms.solution.sum = sol_dist(Algorithms.solution,0);
		avg_weight = (int) (Algorithms.solution.sum / Algorithms.solution.edges.size());
		two_opt((int)((double)avg_weight*.7));
		
		//print_solution();
		
		sysPrintSol(solution);

	}

}
